﻿//////////////////////////////////////////////////////////////////////////////
//
//  Copyright © 1998-2024 Glodon Company Limited.  All rights reserved.
//
//  Use of this software is subject to the terms of the Glodon license
//  agreement provided at the time of installation or download, or which
//  otherwise accompanies this software in either electronic or hard copy form.  
//
//////////////////////////////////////////////////////////////////////////////

#pragma once
#include "NdbObjectMemoryModelNode.h"
#include "GbmpQuickCast.h"
#include "GbmpTypeDefs.h"
#include "GcmpDatabase.h"

namespace gcmp
{
    class ClassId;
    class INdbObjectMemoryModelNodeVisitor;

    //////////////////////////////////////////////////////////////////////////
    class GCMP_DATABASE_EXPORT NdbObjectMemoryModelFixedLengthNode : public NdbObjectMemoryModelNode
    {
        DEFINE_CAST_DERIVED(gcmp::NdbObjectMemoryModelFixedLengthNode, gcmp::NdbObjectMemoryModelNode)
    public:
        NdbObjectMemoryModelFixedLengthNode() noexcept = default;
        NdbObjectMemoryModelFixedLengthNode(const NdbObjectMemoryModelFixedLengthNode& another) = default;
        NdbObjectMemoryModelFixedLengthNode(NdbObjectMemoryModelFixedLengthNode&& another) noexcept = default;
        NdbObjectMemoryModelFixedLengthNode& operator = (const NdbObjectMemoryModelFixedLengthNode & another) = default;
        NdbObjectMemoryModelFixedLengthNode& operator = (NdbObjectMemoryModelFixedLengthNode&& another) noexcept = default;
        virtual ~NdbObjectMemoryModelFixedLengthNode() noexcept = default;

        NdbObjectMemoryModelFixedLengthNode(const ClassId& classId, UInt32 version) noexcept;
    };

    //////////////////////////////////////////////////////////////////////////
    class GCMP_DATABASE_EXPORT NdbObjectMemoryModel8BitsNode : public NdbObjectMemoryModelFixedLengthNode
    {
        DEFINE_CAST_DERIVED(gcmp::NdbObjectMemoryModel8BitsNode, gcmp::NdbObjectMemoryModelFixedLengthNode)
    public:
        NdbObjectMemoryModel8BitsNode() noexcept = default;
        NdbObjectMemoryModel8BitsNode(const NdbObjectMemoryModel8BitsNode& another) = default;
        NdbObjectMemoryModel8BitsNode(NdbObjectMemoryModel8BitsNode&& another) noexcept = default;
        NdbObjectMemoryModel8BitsNode& operator = (const NdbObjectMemoryModel8BitsNode & another) = default;
        NdbObjectMemoryModel8BitsNode& operator = (NdbObjectMemoryModel8BitsNode&& another) noexcept = default;
        ~NdbObjectMemoryModel8BitsNode() noexcept = default;

        NdbObjectMemoryModel8BitsNode(const ClassId& classId, UInt32 version) noexcept;

        // 实现父类NdbObjectMemoryModelNode的纯虚函数
    public:
        virtual NdbObjectMemoryModelNodeType GetType() const override { return NdbObjectMemoryModelNodeType::Fixed8Bits; }

        virtual bool IsLeaf() const override { return true; }

        virtual UInt64 GetDataSize() const override { return sizeof(uint8_t); }

        virtual const void * GetData() const override { return &m_value; }

        virtual void * GetDataForWrite() override { return &m_value; }

        virtual void Accept(INdbObjectMemoryModelNodeVisitor * visitor) override;

        // 对比两个节点是否相同，返回值表示是否继续比较，对叶子节点来说，该值总是true。
        virtual bool Compare(
            const NdbObjectMemoryModelNode& base,
            const std::vector<std::pair<std::wstring, std::wstring>>& attributes,
            const NdbElementExportOrCompareOptions& options,
            int level,
            bool& areEqual,
            bool reportNotEqual,
            std::wostringstream& woss
        ) const override;

    public:
        void* operator new(std::size_t count);
        void operator delete(void* ptr);

    private:
        uint8_t m_value = 0;
    };

    //////////////////////////////////////////////////////////////////////////
    class GCMP_DATABASE_EXPORT NdbObjectMemoryModel16BitsNode : public NdbObjectMemoryModelFixedLengthNode
    {
        DEFINE_CAST_DERIVED(gcmp::NdbObjectMemoryModel16BitsNode, gcmp::NdbObjectMemoryModelFixedLengthNode)
    public:
        NdbObjectMemoryModel16BitsNode() noexcept = default;
        NdbObjectMemoryModel16BitsNode(const NdbObjectMemoryModel16BitsNode& another) = default;
        NdbObjectMemoryModel16BitsNode(NdbObjectMemoryModel16BitsNode&& another) noexcept = default;
        NdbObjectMemoryModel16BitsNode& operator = (const NdbObjectMemoryModel16BitsNode & another) = default;
        NdbObjectMemoryModel16BitsNode& operator = (NdbObjectMemoryModel16BitsNode&& another) noexcept = default;
        ~NdbObjectMemoryModel16BitsNode() noexcept = default;

        NdbObjectMemoryModel16BitsNode(const ClassId& classId, UInt32 version) noexcept;

        // 实现父类NdbObjectMemoryModelNode的纯虚函数
    public:
        virtual NdbObjectMemoryModelNodeType GetType() const override { return NdbObjectMemoryModelNodeType::Fixed16Bits; }

        virtual bool IsLeaf() const override { return true; }

        virtual UInt64 GetDataSize() const override { return sizeof(uint16_t); }

        virtual const void * GetData() const override { return &m_value; }

        virtual void * GetDataForWrite() override { return &m_value; }

        virtual void Accept(INdbObjectMemoryModelNodeVisitor * visitor) override;

        // 对比两个节点是否相同，返回值表示是否继续比较，对叶子节点来说，该值总是true。
        virtual bool Compare(
            const NdbObjectMemoryModelNode& base,
            const std::vector<std::pair<std::wstring, std::wstring>>& attributes,
            const NdbElementExportOrCompareOptions& options,
            int level,
            bool& areEqual,
            bool reportNotEqual,
            std::wostringstream& woss
        ) const override;

    public:
        void* operator new(std::size_t count);
        void operator delete(void* ptr);

    private:
        uint16_t m_value = 0;
    };

    //////////////////////////////////////////////////////////////////////////
    class GCMP_DATABASE_EXPORT NdbObjectMemoryModel32BitsNode : public NdbObjectMemoryModelFixedLengthNode
    {
        DEFINE_CAST_DERIVED(gcmp::NdbObjectMemoryModel32BitsNode, gcmp::NdbObjectMemoryModelFixedLengthNode)
    public:
        NdbObjectMemoryModel32BitsNode() noexcept = default;
        NdbObjectMemoryModel32BitsNode(const NdbObjectMemoryModel32BitsNode& another) = default;
        NdbObjectMemoryModel32BitsNode(NdbObjectMemoryModel32BitsNode&& another) noexcept = default;
        NdbObjectMemoryModel32BitsNode& operator = (const NdbObjectMemoryModel32BitsNode & another) = default;
        NdbObjectMemoryModel32BitsNode& operator = (NdbObjectMemoryModel32BitsNode&& another) noexcept = default;
        ~NdbObjectMemoryModel32BitsNode() = default;

        NdbObjectMemoryModel32BitsNode(const ClassId& classId, UInt32 version) noexcept;

        // 实现父类NdbObjectMemoryModelNode的纯虚函数
    public:
        virtual NdbObjectMemoryModelNodeType GetType() const override { return NdbObjectMemoryModelNodeType::Fixed32Bits; }

        virtual bool IsLeaf() const override { return true; }

        virtual UInt64 GetDataSize() const override { return sizeof(uint32_t); }

        virtual const void * GetData() const override { return &m_value; }

        virtual void * GetDataForWrite() override { return &m_value; }

        virtual void Accept(INdbObjectMemoryModelNodeVisitor * visitor) override;

        // 对比两个节点是否相同，返回值表示是否继续比较，对叶子节点来说，该值总是true。
        virtual bool Compare(
            const NdbObjectMemoryModelNode& base,
            const std::vector<std::pair<std::wstring, std::wstring>>& attributes,
            const NdbElementExportOrCompareOptions& options,
            int level,
            bool& areEqual,
            bool reportNotEqual,
            std::wostringstream& woss
        ) const override;

    public:
        void* operator new(std::size_t count);
        void operator delete(void* ptr);

    private:
        uint32_t m_value = 0;
    };

    //////////////////////////////////////////////////////////////////////////
    class GCMP_DATABASE_EXPORT NdbObjectMemoryModel64BitsNode : public NdbObjectMemoryModelFixedLengthNode
    {
        DEFINE_CAST_DERIVED(gcmp::NdbObjectMemoryModel64BitsNode, gcmp::NdbObjectMemoryModelFixedLengthNode)
    public:
        NdbObjectMemoryModel64BitsNode() noexcept = default;
        NdbObjectMemoryModel64BitsNode(const NdbObjectMemoryModel64BitsNode& another) = default;
        NdbObjectMemoryModel64BitsNode(NdbObjectMemoryModel64BitsNode&& another) noexcept = default;
        NdbObjectMemoryModel64BitsNode& operator = (const NdbObjectMemoryModel64BitsNode & another) = default;
        NdbObjectMemoryModel64BitsNode& operator = (NdbObjectMemoryModel64BitsNode&& another) noexcept = default;
        ~NdbObjectMemoryModel64BitsNode() = default;

        NdbObjectMemoryModel64BitsNode(const ClassId& classId, UInt32 version) noexcept;

        // 实现父类NdbObjectMemoryModelNode的纯虚函数
    public:
        virtual NdbObjectMemoryModelNodeType GetType() const override { return NdbObjectMemoryModelNodeType::Fixed64Bits; }

        virtual bool IsLeaf() const override { return true; }

        virtual UInt64 GetDataSize() const override { return sizeof(uint64_t); }

        virtual const void * GetData() const override { return &m_value; }

        virtual void * GetDataForWrite() override { return &m_value; }

        virtual void Accept(INdbObjectMemoryModelNodeVisitor * visitor) override;

        // 对比两个节点是否相同，返回值表示是否继续比较，对叶子节点来说，该值总是true。
        virtual bool Compare(
            const NdbObjectMemoryModelNode& base,
            const std::vector<std::pair<std::wstring, std::wstring>>& attributes,
            const NdbElementExportOrCompareOptions& options,
            int level,
            bool& areEqual,
            bool reportNotEqual,
            std::wostringstream& woss
        ) const override;

    public:
        void* operator new(std::size_t count);
        void operator delete(void* ptr);

    private:
        uint64_t m_value = 0;
    };

    //////////////////////////////////////////////////////////////////////////
    class GCMP_DATABASE_EXPORT NdbObjectMemoryModelDoubleNode : public NdbObjectMemoryModelFixedLengthNode
    {
        DEFINE_CAST_DERIVED(gcmp::NdbObjectMemoryModelDoubleNode, gcmp::NdbObjectMemoryModelFixedLengthNode)
    public:
        NdbObjectMemoryModelDoubleNode() noexcept = default;
        NdbObjectMemoryModelDoubleNode(const NdbObjectMemoryModelDoubleNode& another) = default;
        NdbObjectMemoryModelDoubleNode(NdbObjectMemoryModelDoubleNode&& another) noexcept = default;
        NdbObjectMemoryModelDoubleNode& operator = (const NdbObjectMemoryModelDoubleNode & another) = default;
        NdbObjectMemoryModelDoubleNode& operator = (NdbObjectMemoryModelDoubleNode&& another) noexcept = default;
        ~NdbObjectMemoryModelDoubleNode() = default;

        NdbObjectMemoryModelDoubleNode(const ClassId& classId, UInt32 version) noexcept;

        // 实现父类NdbObjectMemoryModelNode的纯虚函数
    public:
        virtual NdbObjectMemoryModelNodeType GetType() const override { return NdbObjectMemoryModelNodeType::FixedDouble; }

        virtual bool IsLeaf() const override { return true; }

        virtual UInt64 GetDataSize() const override { return sizeof(double); }

        virtual const void * GetData() const override { return &m_value; }

        virtual void * GetDataForWrite() override { return &m_value; }

        virtual void Accept(INdbObjectMemoryModelNodeVisitor * visitor) override;

        // 对比两个节点是否相同，返回值表示是否继续比较，对叶子节点来说，该值总是true。
        virtual bool Compare(
            const NdbObjectMemoryModelNode& base,
            const std::vector<std::pair<std::wstring, std::wstring>>& attributes,
            const NdbElementExportOrCompareOptions& options,
            int level,
            bool& areEqual,
            bool reportNotEqual,
            std::wostringstream& woss
        ) const override;

    public:
        void* operator new(std::size_t count);
        void operator delete(void* ptr);

    private:
        double m_value = 0.0;
    };

    //////////////////////////////////////////////////////////////////////////
    class GCMP_DATABASE_EXPORT NdbObjectMemoryModelFloatNode : public NdbObjectMemoryModelFixedLengthNode
    {
        DEFINE_CAST_DERIVED(gcmp::NdbObjectMemoryModelFloatNode, gcmp::NdbObjectMemoryModelFixedLengthNode)
    public:
        NdbObjectMemoryModelFloatNode() noexcept = default;
        NdbObjectMemoryModelFloatNode(const NdbObjectMemoryModelFloatNode& another) = default;
        NdbObjectMemoryModelFloatNode(NdbObjectMemoryModelFloatNode&& another) noexcept = default;
        NdbObjectMemoryModelFloatNode& operator = (const NdbObjectMemoryModelFloatNode & another) = default;
        NdbObjectMemoryModelFloatNode& operator = (NdbObjectMemoryModelFloatNode&& another) noexcept = default;
        ~NdbObjectMemoryModelFloatNode() noexcept = default;

        NdbObjectMemoryModelFloatNode(const ClassId& classId, UInt32 version) noexcept;

        // 实现父类NdbObjectMemoryModelNode的纯虚函数
    public:
        virtual NdbObjectMemoryModelNodeType GetType() const override { return NdbObjectMemoryModelNodeType::FixedFloat; }

        virtual bool IsLeaf() const override { return true; }

        virtual UInt64 GetDataSize() const override { return sizeof(float); }

        virtual const void * GetData() const override { return &m_value; }

        virtual void * GetDataForWrite() override { return &m_value; }

        virtual void Accept(INdbObjectMemoryModelNodeVisitor * visitor) override;

        // 对比两个节点是否相同，返回值表示是否继续比较，对叶子节点来说，该值总是true。
        virtual bool Compare(
            const NdbObjectMemoryModelNode& base,
            const std::vector<std::pair<std::wstring, std::wstring>>& attributes,
            const NdbElementExportOrCompareOptions& options,
            int level,
            bool& areEqual,
            bool reportNotEqual,
            std::wostringstream& woss
        ) const override;

    public:
        void* operator new(std::size_t count);
        void operator delete(void* ptr);

    private:
        float m_value = 0.0f;
    };
}
